Questions
10 of 25
1How do you implement a local (username/password) Passport strategy in NestJS?
2How do you register a global JWT guard so all routes are protected by default in NestJS?
3What is RBAC and how do you implement a basic roles guard in NestJS?
4What is the difference between RBAC and ABAC and when would you use each in NestJS?
5How does the OAuth2 authorization code flow work and how do you implement it with Passport in NestJS?
6How do you implement API key authentication as an alternative to JWT in NestJS?
7How do you implement multi-tenant authentication where each tenant has its own JWT secret in NestJS?
8How do you implement JWT refresh token rotation with secure storage in NestJS?
9How do you implement ABAC with CASL in a NestJS application?
10What is the difference between JWT and session-based authentication and when do you choose each in NestJS?
11How do you implement two-factor authentication (2FA) with TOTP in NestJS?
12How do you implement permission-based authorization at the field level in a GraphQL resolver in NestJS?
13How do you test authentication guards and strategies in NestJS?
14What is Passport.js and how does it integrate with NestJS?
15How do you implement row-level (resource-level) authorization to ensure users can only access their own records in NestJS?
16What is PKCE and when is it required in OAuth2 flows in NestJS?
17How do you implement an OAuth2 Authorization Server in NestJS?
18How do you implement session-based authentication in NestJS?
19How does the validate() method in a Passport strategy relate to the NestJS request lifecycle?
20How do you implement JWT authentication in NestJS with access and refresh tokens?
21What should and should not go inside a JWT payload?
22How do you implement JWT token revocation (blacklisting) without a database lookup on every request in NestJS?
23What is the difference between AuthGuard('jwt') from Passport and writing a custom JwtAuthGuard in NestJS?
24How do you secure session cookies against common attacks (CSRF, XSS, session fixation) in NestJS?
25How do you implement brute force protection on the login endpoint in NestJS?
10 / 25

What is the difference between JWT and session-based authentication and when do you choose each in NestJS?

JWT is stateless — all state in the token, trivial horizontal scaling, but revocation requires a blacklist. Sessions are stateful — state in Redis, instant revocation by deleting the session, but require a shared store across instances. Use JWT for APIs and SPAs; use sessions for server-rendered apps and compliance requirements.

The fundamental trade-off is statefulness. JWT externalizes state to the client — the server has no record of issued tokens. Sessions centralize state in a shared store — every instance can revoke a session immediately by deleting it.

Decision guide — JWT vs sessions:
  1. 1

    Choose JWT for: stateless horizontal scaling, microservices that verify tokens independently, SPAs and mobile clients, short-lived tokens (15m) with refresh token rotation.

  2. 2

    Choose sessions for: server-rendered apps (Next.js SSR), immediate logout as a hard requirement, B2B apps where admins must terminate any session instantly, HIPAA and SOC2 compliance requiring auditable active sessions.

  3. 3

    JWT limitation: revocation requires a Redis blacklist — short expiry and refresh rotation are the primary mitigations.

  4. 4

    Session limitation: requires sticky sessions or a shared Redis store — adds operational complexity.

  5. 5

    Hybrid approach: use sessions for browser clients and JWT for API/mobile clients with a guard that accepts either.